package com.eshop.controller.order;

import com.eshop.pojo.Order;
import com.eshop.pojo.RespBean;
import com.eshop.pojo.RespPageBean;
import com.eshop.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "历史订单管理相关")
@RestController
@RequestMapping("/order/history")
public class OrderHistoryController {
    @Autowired
    OrderService orderService;

    //分页获取历史订单列表
    @ApiOperation("分页获取历史订单")
    @GetMapping("/")
    public RespPageBean getHistoryOrderByPage(@RequestParam(defaultValue = "1") Integer currentPage,
                                           @RequestParam(defaultValue = "8") Integer size, Order order) {
        return orderService.getHistoryOrderByPage(currentPage, size,order);
    }

    //分页获取历史订单列表
    @ApiOperation("顾客分页获取历史订单")
    @GetMapping("/customer")
    public RespPageBean getHistoryOrderByPageC(@RequestParam(defaultValue = "1") Integer currentPage,
                                              @RequestParam(defaultValue = "8") Integer size, Order order) {
        return orderService.getHistoryOrderByPageC(currentPage, size,order);
    }

    //分页获取历史订单列表
    @ApiOperation("顾客分页获取历史所有订单")
    @GetMapping("/customer/all")
    public RespPageBean getHistoryOrderByPageCA(@RequestParam(defaultValue = "1") Integer currentPage,
                                               @RequestParam(defaultValue = "8") Integer size, Order order) {
        return orderService.getHistoryOrderByPageCA(currentPage, size,order);
    }

    @ApiOperation("删除历史订单")
    @DeleteMapping("/{id}")
    public RespBean deteleHistoryOrderById(@PathVariable int id){
        if (orderService.deteleHistoryOrderById(id) == 1){
            return RespBean.success("订单删除成功！");
        }
        return RespBean.error("订单删除失败！");
    }
}
